//
//  MyCustomCell.m
//  CustomCellExample
//

#import "MyCustomCell.h"

@implementation MyCustomCell

@synthesize view;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setView:(UIView *)aView {
	if (view)
		[view removeFromSuperview];
	view = aView;
	[self.view retain];
	[self.contentView addSubview:aView];
	
	[self layoutSubviews];
}

- (void)layoutSubviews {
	float xOffset = 10.0;
	
	[super layoutSubviews];
	CGRect contentRect = [self.contentView bounds];
	
	CGRect viewFrame = CGRectMake(contentRect.size.width - self.view.bounds.size.width - xOffset,
								  round((contentRect.size.height - self.view.bounds.size.height) / 2.0),
								  self.view.bounds.size.width, self.view.bounds.size.height);
	view.frame = viewFrame;
}

- (void)dealloc {
	[view release];
    [super dealloc];
}

@end
